package com.wiretrack.circuit;

import java.awt.EventQueue;

import javax.swing.JFrame;
import java.awt.BorderLayout;
import java.awt.Component;

import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.JProgressBar;
import javax.swing.JPanel;
import java.awt.Font;
import javax.swing.AbstractAction;
import java.awt.event.ActionEvent;
import javax.swing.Action;
import javax.swing.JPopupMenu;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JMenu;

public class AnotherGui
{

	private JFrame frame;
	private final Action action = new SwingAction();
	private final Action action_1 = new SwingAction_1();
	private JPanel panel;
	private JProgressBar progressBar;
	private JLabel lblNewLabel_1;
	private JLabel lblNewLabel_3;
	private JPanel panel_1;
	private JLabel lblNewLabel;
	private JLabel lblNewLabel_2;
	private JMenuBar menuBar;
	private JMenu mnMenu;
	private JMenuItem mntmFile;
	private JMenuItem mntmExit;
	private JMenuItem mntmPause;
	private JMenuItem mntmStart;
	private JMenuBar menuBar_1;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args)
	{
		EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{
				try
				{
					AnotherGui window = new AnotherGui();
					window.frame.setVisible(true);
				}
				catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public AnotherGui()
	{
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize()
	{
		frame = new JFrame();
		frame.setBounds(100, 100, 558, 440);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		panel = new JPanel();
		frame.getContentPane().add(panel, BorderLayout.CENTER);
		panel.setLayout(new BorderLayout(0, 0));

		lblNewLabel_1 = new JLabel("1");
		lblNewLabel_1.setFont(new Font("Dialog", Font.BOLD, 78));
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
		panel.add(lblNewLabel_1, BorderLayout.CENTER);

		panel_1 = new JPanel();
		panel.add(panel_1, BorderLayout.SOUTH);
		panel_1.setLayout(new BorderLayout(0, 0));

		lblNewLabel = new JLabel("Description");
		lblNewLabel.setFont(new Font("Dialog", Font.PLAIN, 26));
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		panel_1.add(lblNewLabel, BorderLayout.NORTH);

		lblNewLabel_2 = new JLabel("next...");
		lblNewLabel_2.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 24));
		lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
		panel_1.add(lblNewLabel_2, BorderLayout.SOUTH);

		progressBar = new JProgressBar();
		progressBar.setStringPainted(true);
		frame.getContentPane().add(progressBar, BorderLayout.SOUTH);

		lblNewLabel_3 = new JLabel("Name");
		lblNewLabel_3.setFont(new Font("Dialog", Font.BOLD, 36));
		lblNewLabel_3.setHorizontalAlignment(SwingConstants.CENTER);
		frame.getContentPane().add(lblNewLabel_3, BorderLayout.NORTH);

		menuBar = new JMenuBar();
		frame.setJMenuBar(menuBar);

		mnMenu = new JMenu("Menu");
		menuBar.add(mnMenu);

		mntmFile = new JMenuItem("Open");
		mntmFile.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				System.out.println("Open");
				final JFileChooser fc = new JFileChooser();
				int returnVal = fc.showOpenDialog(panel);
				
				if ( returnVal == JFileChooser.APPROVE_OPTION )
				{
					File file = fc.getSelectedFile();
					System.out.println("Opening: " + file.getName());
				}
				else
				{
					System.out.println("Open command cancelled by user.");
				}
			}
		});
		mnMenu.add(mntmFile);

		mntmStart = new JMenuItem("Start");
		mntmStart.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				System.out.println("Starting....");
			}
		});
		mnMenu.add(mntmStart);

		mntmPause = new JMenuItem("Pause");
		mntmPause.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				System.out.println("Paused...");
			}
		});
		mnMenu.add(mntmPause);

		mntmExit = new JMenuItem("Exit");
		mntmExit.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				System.out.println("Exiting...");
				System.exit(0);
			}
		});
		mnMenu.add(mntmExit);
		
		menuBar_1 = new JMenuBar();
		menuBar.add(menuBar_1);
	}

	private class SwingAction extends AbstractAction
	{
		public SwingAction()
		{
			putValue(NAME, "SwingAction");
			putValue(SHORT_DESCRIPTION, "Some short description");
		}

		public void actionPerformed(ActionEvent e)
		{
			System.out.println("here");

			progressBar.setString("10%");
			progressBar.setValue(10);
		}
	}

	private static void addPopup(Component component, final JPopupMenu popup)
	{
		component.addMouseListener(new MouseAdapter()
		{
			public void mousePressed(MouseEvent e)
			{
				if ( e.isPopupTrigger() )
				{
					showMenu(e);
				}
			}

			public void mouseReleased(MouseEvent e)
			{
				if ( e.isPopupTrigger() )
				{
					showMenu(e);
				}
			}

			private void showMenu(MouseEvent e)
			{
				popup.show(e.getComponent(), e.getX(), e.getY());
			}
		});
	}

	private class SwingAction_1 extends AbstractAction
	{
		public SwingAction_1()
		{
			putValue(NAME, "SwingAction_1");
			putValue(SHORT_DESCRIPTION, "Some short description");
		}

		public void actionPerformed(ActionEvent e)
		{
			System.out.println("here menu");
		}
	}
}
